package com.ayf.payment.game.api.exception;

import java.text.MessageFormat;

/**
 * @Description: 逻辑异常类
 * @Author: zh-liang
 * @Date : 2020-04-21 16:45
 */
public class LogicalException extends RuntimeException {

    private String traceId;
    private String msg;

    public LogicalException(String msg, Object... obj) {
        this.msg = format(msg, obj);
        this.traceId = obj[0].toString();
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    private static String format(String msg, Object... obj) {
        String str = "";
        for (int i = 0; i < obj.length; i++) {
            msg = msg.replaceFirst("\\{}", "{" + i + "}");
        }
        return MessageFormat.format(msg, obj);
    }
}
